<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-inline">
                                <select name="sex" lay-search="">
                                    <option value="">直接选择或搜索选择</option>
                                    <option value="男">男</option>
                                    <option value="女">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">年龄</label>
                            <div class="layui-input-inline">
                                <select name="age" lay-search="">
                                    <option value="">直接选择或搜索选择</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                                    <option value="13">13</option>
                                    <option value="14">14</option>
                                    <option value="15">15</option>
                                    <option value="16">16</option>
                                    <option value="17">17</option>
                                    <option value="18">18</option>
                                    <option value="19">19</option>
                                    <option value="20">20</option>
                                    <option value="21">21</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加学生信息 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="study">学习档案</a>
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="sport">运动档案</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="practice">实践档案</a>
            <a class="layui-btn layui-btn-primary layui-btn-xs data-count-edit" lay-event="health">健康档案</a>
            <a class="layui-btn layui-bg-black layui-btn-xs data-count-edit" lay-event="evaluation">综合评价</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs data-count-edit" lay-event="edit" style="margin-left: 3%">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        form.render();
        table.render({
            elem: '#currentTableId',
            url: 'student/studentInfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'sid', width: 150, title: '学号', sort: true},
                {field: 'sname', width: 150, title: '姓名'},
                {field: 'ssex', width: 80, title: '性别', sort: true},
                {field: 'sage', width: 120, title: '年龄',minWidth: 40},
                {field: 'stime', width: 120,title: '录入日期', minWidth: 40},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    sex: data.field.sex,
                    age: data.field.age
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {   // 监听添加操作
                var content = miniPage.getHrefContent('teacher/addStudent.html');
                var index = layer.open({
                    title: '添加学生',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%','50%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if(obj.event === 'study'){
                var content = miniPage.getHrefContent('studyShow?sid='+data.sid+'&sname='+data.sname);
                layer.open({
                    title: '学习档案',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%','80%'],
                    content:content
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }else if(obj.event === 'sport'){
                var content = miniPage.getHrefContent('sportShow?sid='+data.sid+'&sname='+data.sname);
                layer.open({
                    title: '运动档案',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%','80%'],
                    content:content
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }else if(obj.event === 'practice'){
                var content = miniPage.getHrefContent('practiceShow?sid='+data.sid+'&sname='+data.sname);
                layer.open({
                    title: '实践档案',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%','80%'],
                    content:content
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }else if(obj.event === 'health'){
                var content = miniPage.getHrefContent('healthShow?sid='+data.sid+'&sname='+data.sname);
                layer.open({
                    title: '健康档案',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%','80%'],
                    content:content
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }else if(obj.event === 'evaluation'){
                var content = miniPage.getHrefContent('evaluationShow?sid='+data.sid+'&sname='+data.sname);
                layer.open({
                    title: '综合评价',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%','80%'],
                    content:content
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }
            else if (obj.event === 'edit') {
                var content = miniPage.getHrefContent('updateStudent?id='+data.sid+'&name='+data.sname+'&age='+data.sage+'&sex='+data.ssex);
                var index = layer.open({
                    title: '编辑学生',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%','50%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: 'student/deleteStudent',
                        type:'POST',
                        data:{
                            sid:data.sid
                        },
                        success:function (res){
                            if(res.code==200){
                                layer.close(index);
                                layer.msg("删除成功!");
                                parent.window.location.reload();
                            }else {
                                layer.msg("删除失败！");
                            }
                        }

                    })
                });
            }
        });

    });
</script>